class SettingsController < ApplicationController
  before_filter :require_login
  before_filter :require_admin
  
  def index
    @photo_sizes      = PhotoSize.find(:all)
    @photo_size       = PhotoSize.new
    @item_options     = ItemOption.find(:all)
    @item_option      = ItemOption.new
    @order_options    = OrderOption.find(:all)
    @order_option     = OrderOption.new
    @shipping_methods = ShippingMethod.find(:all, :order => 'cost asc')
    @shipping_method  = ShippingMethod.new
    @menu_items       = Menu.find(:all)
    @menu_item        = Menu.new
    @price_lists      = PriceList.find(:all)
    @price_list       = PriceList.new
    @random_photos    = Photo.find(:all, :conditions => ['random = ?', true])
    @random_videos    = Video.find(:all, :conditions => ['random = ?', true])
  end

protected
  def require_login
    unless logged_in?
      flash[:error] = 'You must be logged in to do that'
      redirect_to login_url
    end
  end
  def require_admin
    unless current_user.is_admin?
      flash[:error] = "Must be an administrator to do that, sorry."
      redirect_back_or_default('/')
    end
  end
end
